﻿/*
 * WARNING: THIS EXAMPLE WORKS ONLY IF CONTENT IS IN TestContent PROJECT!!
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DynSim;
using DynSim.Entities;
using DynSim.Basics;
using DynSim.EntityFramework;
using Microsoft.Xna.Framework;

namespace DSSViewer
{
    public partial class MainForm : Form
    {
        FormGame game;

        public MainForm()
        {
            InitializeComponent();

            game = new FormGame();
            dynSimViewer1.RunGame(game);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("DSS Scene Viewer\nCopyright 2011 Dyn Systems", "About", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dynSimViewer1.StopGame();
        }

        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                game.engine.entities = new EntityCollection();

                game.engine.entities.AddRangeAndInitialize(SceneReader.Load(dlg.FileName).entities.ToArray());
            }
        }
    }

    class FormGame : Game
    {
        public BaseEngine engine;

        protected override void Initialize()
        {
            engine = new BaseEngine(this);
            engine.camera = new Camera(new Vector3(0), new Vector3(0, 0, 1), 1f, (float)engine.graphics.PreferredBackBufferWidth / (float)engine.graphics.PreferredBackBufferHeight, 0.1f, 1000000f);

            base.Initialize();
        }
    }
}
